package com.heer.gymnasium.activity;

import android.content.Context;
import android.content.Intent;
import android.text.TextUtils;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import com.heer.api.ResponseData.ApiResponse;
import com.heer.api.constants.StaticValue;
import com.heer.gymnasium.R;
import com.heer.gymnasium.constant.Type;
import com.heer.gymnasium.event.BaseEvent;
import com.heer.gymnasium.util.ShareUtils;
import com.heer.model.OrderBean;

import org.greenrobot.eventbus.EventBus;

import java.util.List;

import butterknife.BindView;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

import static com.heer.gymnasium.event.EventConstant.CREATE_ORDER;

/**
 * Created by admin on 2017/8/3.
 */

public class PaySucceedActivity extends BaseActivity implements View.OnClickListener{

    @BindView(R.id.tv_pays_context)
    TextView tv_context;

    @BindView(R.id.btn_pays_order)
    Button btn_order;

    @BindView(R.id.btn_pays_share)
    Button btn_share;

    String orderid;

    @Override
    protected void init() {
        super.init();
        setContentView(R.layout.activity_pay_succeed);
    }

    @Override
    protected void initView() {
        super.initView();
        btn_order.setOnClickListener(this);
        btn_share.setOnClickListener(this);
        titleBuilder.setTitleText("支付结果");
    }

    @Override
    protected void loadData() {
        super.loadData();
        mAppHelper.apiService().getOrderList(
                StaticValue.payOrderid,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                null,
                "1"
        ).enqueue(new Callback<ApiResponse<List<OrderBean>>>() {
            @Override
            public void onResponse(Call<ApiResponse<List<OrderBean>>> call, Response<ApiResponse<List<OrderBean>>> response) {
                if (response.isSuccessful() && response.body().isSccessful())
                {
                    orderid=response.body().getData().get(0).getOrder_sn();
                    tv_context.setText(response.body().getData().get(0).getStadium().getStadiumname());
                    if (TextUtils.equals(response.body().getData().get(0).getTicket().getCat_id(), Type.SITE_TICKET_TYPE_4))
                    {
                        btn_share.setVisibility(View.VISIBLE);
                    }else {
                        btn_share.setVisibility(View.GONE);
                    }
                }
            }

            @Override
            public void onFailure(Call<ApiResponse<List<OrderBean>>> call, Throwable t) {

            }
        });
    }

    @Override
    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.btn_pays_order:
                Intent intent = new Intent("com.heer.gymnasium.activity.MainActivity");
                //intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP|Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("index",1);
                startActivity(intent);
                BaseEvent event = new BaseEvent(CREATE_ORDER,"");
                EventBus.getDefault().post(event);
                break;
            case R.id.btn_pays_share:
                ShareUtils.showShare(this, ShareUtils.getShareUrl(orderid),"入场电子门票");
                break;
        }
    }
    public static void StartPaySucceed(Context context)
    {
        Intent intent=new Intent(context,PaySucceedActivity.class);
        context.startActivity(intent);

    }
}
